package cn.hallele.leinsteining.mc.infrastructure.metadata.io;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * Metric
 *
 * @author anle5
 * @since 2024/7/26 0:07
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "响应体指标")
public class Metric implements Serializable {
    @Serial
    private static final long serialVersionUID = -5965031349224499130L;

    /**
     * 前端通过该字段判断是否处理成功
     * true 处理成功, false 处理失败
     */
    @Schema(description = "业务处理成功标识")
    private boolean success;

    /**
     * 消息码
     */
    @Schema(description = "消息码")
    private String msgCode;

    /**
     * 消息描述 语言国际化后的对应msgCode的描述
     */
    @Schema(description = "消息描述")
    private String msgDesc;

    /**
     * 客户端ip
     */
    @Schema(description = "客户端ip")
    private String ip;

    /**
     * 客户端设备
     */
    @Schema(description = "客户端设备")
    private String accessDevice;

    /**
     * 响应时间
     */
    @Schema(description = "响应时间")
    private LocalDateTime completedTime;

    /**
     * accessDevice 为空的时候才会赋值
     *
     * @param accessDevice accessDevice
     */
    public void setAccessDeviceIfBlank(String accessDevice) {
        if (StringUtils.isBlank(this.accessDevice)) {
            this.accessDevice = accessDevice;
        }
    }

    /**
     * ip 为空的时候才会赋值
     *
     * @param ip ip
     */
    public void setIpIfBlank(String ip) {
        if (StringUtils.isBlank(this.ip)) {
            this.ip = ip;
        }
    }
}
